cmake_minimum_required(VERSION 3.0)
project(fake-os VERSION 0.0.2)

set(LIB scheduler memory)
set(LIB_TEST scheduler_test memory_test)

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

configure_file(${PROJECT_SOURCE_DIR}/include/config.h.in ${PROJECT_SOURCE_DIR}/include/config.h)

# Build Scheduler
add_subdirectory(${PROJECT_SOURCE_DIR}/scheduler)
add_subdirectory(${PROJECT_SOURCE_DIR}/memory)
aux_source_directory(${PROJECT_SOURCE_DIR}/src SRC)
add_executable(${PROJECT_NAME} ${SRC})
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_compile_options(${PROJECT_NAME} PUBLIC -pthread)
target_link_libraries(${PROJECT_NAME} pthread ${LIB})

if(CMAKE_BUILD_TYPE STREQUAL "Debug")

    target_compile_options(${PROJECT_NAME} PUBLIC -DDEBUG -g)

    find_package(GTest REQUIRED)
    if(GTEST_FOUND)    
        add_executable(unit_tests ${SRC})
        target_compile_options(unit_tests PUBLIC -DDEBUG PUBLIC -DUNIT_TEST)
        target_include_directories(unit_tests PUBLIC ${PROJECT_SOURCE_DIR}/include ${GTEST_INCLUDE_DIRS})
        target_link_libraries(unit_tests ${LIB_TEST} ${GTEST_BOTH_LIBRARIES} pthread)
    endif(GTEST_FOUND)
    
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")

# demo build

# SSTF-demo
add_executable(SSTF-demo 
    ${PROJECT_SOURCE_DIR}/demo/SSTF-demo.cpp
    ${PROJECT_SOURCE_DIR}/src/cpu.cpp
    ${PROJECT_SOURCE_DIR}/src/peripheral.cpp)
target_include_directories(SSTF-demo 
    PUBLIC ${PROJECT_SOURCE_DIR}/include
    PUBLIC ${PROJECT_SOURCE_DIR}/scheduler/include)
target_compile_options(SSTF-demo PUBLIC -DDEBUG PUBLIC -pthread)
target_link_libraries(SSTF-demo pthread)

# memory-demo
add_executable(memory-demo 
    ${PROJECT_SOURCE_DIR}/demo/memory-demo.cpp)
target_include_directories(memory-demo 
    PUBLIC ${PROJECT_SOURCE_DIR}/include
    PUBLIC ${PROJECT_SOURCE_DIR}/memory/include)
target_compile_options(memory-demo PUBLIC -DDEBUG PUBLIC -pthread)
target_link_libraries(memory-demo pthread memory)

#print-demo
add_executable(print-demo 
    ${PROJECT_SOURCE_DIR}/demo/print-demo.cpp
    ${PROJECT_SOURCE_DIR}/src/cpu.cpp
    ${PROJECT_SOURCE_DIR}/src/semaphores.cpp)
target_include_directories(print-demo 
    PUBLIC ${PROJECT_SOURCE_DIR}/include
    PUBLIC ${PROJECT_SOURCE_DIR}/scheduler/include)
target_compile_options(print-demo PUBLIC -DDEBUG PUBLIC -pthread)
target_link_libraries(print-demo scheduler pthread)
